//
//  HRPostSoundViewModel.m
//  Hear
//
//  Created by mac on 2017/4/7.
//  Copyright © 2017年 mac. All rights reserved.
//

#import "HRPostSoundViewModel.h"
#import "HRPostSoundModel.h"
@implementation HRPostSoundViewModel

#pragma 发布一个声音
-(void)postSoundParam:(HRPostSoundRequestModel *)requstModel isSeccess:(void(^)(BOOL isSeccess))isSeccess{
    YTKApi *api = [YTKApi apiPostWithUrl:@"SoundInfo/Post_SaveSound" parameter:requstModel];
    [api getSuccessToken:^() {
        api.foceNoTocken = NO;
        [api setRequestSerializerType:YTKRequestSerializerTypeHTTP];
        [api startWithCompletionBlockWithSuccess:^(__kindof YTKBaseRequest * _Nonnull request) {
            
            NSDictionary *dict = request.responseJSONObject;
            
            
            NSDictionary *contentDict = [dict[@"BodyContent"] jsonValueDecoded];

            isSeccess(YES);
        } failure:^(__kindof YTKBaseRequest * _Nonnull request) {
            isSeccess(NO);
        }];
    }];
}




#pragma 保存收听声音记录
-(void)saveSoundRecordParam:(HRBaseRequstDataModel *)requstModel isSeccess:(void(^)(BOOL isSeccess))isSeccess{
    YTKApi *api = [YTKApi apiPostWithUrl:@"SoundInfo/Post_SaveSoundRecord" parameter:requstModel];
    [api getSuccessToken:^() {
        api.foceNoTocken = NO;
        [api setRequestSerializerType:YTKRequestSerializerTypeHTTP];
        [api startWithSuccess:^(YTKBaseRequest *request) {
            NSDictionary *dict = request.responseJSONObject;
            
            // BodyContent
            if ([dict[@"CodeStatus"] intValue] == 20000){
                isSeccess(YES);
            }else{
                isSeccess(NO);
            }
        }];
    }];
}

#pragma 用户话题保存接口
-(void)saveUserTopicParam:(NSMutableDictionary *)requstDict isSeccess:(void(^)(BOOL isSeccess))isSeccess{
    YTKApi *api = [YTKApi apiPostWithUrl:@"UserInfo/Post_SaveUserTopic" para:requstDict];
    [api getSuccessToken:^() {
        api.foceNoTocken = NO;
        [api setRequestSerializerType:YTKRequestSerializerTypeHTTP];
        [api startWithSuccess:^(YTKBaseRequest *request) {
            NSDictionary *dict = request.responseJSONObject;
            
            // BodyContent
            if ([dict[@"CodeStatus"] intValue] == 20000){
                isSeccess(YES);
            }else{
                [MBProgressHUD showMessage:dict[@"Message"] finishBlock:nil];
                isSeccess(NO);
            }
        }];
    }];
}

#pragma 用户话题重新保存接口
-(void)setUserTopicUsable:(NSMutableDictionary *)requstDict isSeccess:(void(^)(BOOL isSeccess))isSeccess{
    YTKApi *api = [YTKApi apiPutWithUrl:@"UserInfo/Put_SetUserTopicUsable" para:requstDict];
    [api getSuccessToken:^() {
        api.foceNoTocken = NO;
        [api setRequestSerializerType:YTKRequestSerializerTypeHTTP];
        [api startWithSuccess:^(YTKBaseRequest *request) {
            NSDictionary *dict = request.responseJSONObject;
            
            // BodyContent
            if ([dict[@"CodeStatus"] intValue] == 20000){
                isSeccess(YES);
            }else{
                [MBProgressHUD showMessage:dict[@"Message"] finishBlock:nil];
                isSeccess(NO);
            }
        }];
    }];
}
#pragma 用户话题删除接口
-(void)deleteUserTopic:(NSMutableDictionary *)requstDict isSeccess:(void(^)(BOOL isSeccess))isSeccess{
    YTKApi *api = [YTKApi apiDeleteWithUrl:@"UserInfo/Delete_DeleteUserTopic" para:requstDict];
    [api getSuccessToken:^() {
        api.foceNoTocken = NO;
        [api setRequestSerializerType:YTKRequestSerializerTypeHTTP];
        [api startWithSuccess:^(YTKBaseRequest *request) {
            NSDictionary *dict = request.responseJSONObject;
            
            // BodyContent
            if ([dict[@"CodeStatus"] intValue] == 20000){
                isSeccess(YES);
            }else{
                [MBProgressHUD showMessage:dict[@"Message"] finishBlock:nil];
                isSeccess(NO);
            }
        }];
    }];
}


@end
